package cn.jiyun.controller;

import cn.jiyun.pojo.User;
import cn.jiyun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("regist")
    public String regist(){

        return "regist.html";
    }
    @RequestMapping("toregist")
    public String toregist(@RequestBody User user){
        String result="SUCC";
       try {
           userService.addUser(user);
       }catch (Exception e){
           e.printStackTrace();
           result = "FAIL";
        }
       return result;
    }
    @RequestMapping("login")
    public String login(){
        return "login.html";
    }
    @RequestMapping("toLogin")
    public String toLogin(@RequestBody User user){
        String result="SUCC";
        try {
            User u=userService.findByNameAndPwd(user);
            if (u==null){
                result="FAIL";
            }else {
                result="SUCC";
            }
        }catch (Exception e){
            e.printStackTrace();
            result = "FAIL";
        }
        return result;
    }
    @RequestMapping("getAllYunying")
    public String getAllYunying(){
        return "list1.html";
    }
    @RequestMapping("getAllZhongxin")
    public String getAllZhongxin(){
        return "list2.html";
    }

}
